package com.op.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.op.entity.QuestionBankAudit;
import com.op.model.vo.QuestionBankReviewVo;
import com.op.response.ResponseResult;
import com.op.service.QuestionBankAuditService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QuestionBankAudit)表控制层
 *
 * @author 孤焰
 * @since 2021-12-11 19:28:04
 */
@RestController
@RequestMapping("/questionBankAudit")
public class QuestionBankAuditController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionBankAuditService questionBankAuditService;

    /**
     * 分页联表查询所有数据
     * @param page              分页对象
     * @param questionBankAudit 查询实体
     * @return 所有数据（分页）
     */
    @GetMapping("/joinPage")
    public ResponseResult<Page<QuestionBankReviewVo>> joinPage(Page<QuestionBankAudit> page, QuestionBankAudit questionBankAudit) {
        return ResponseResult.success(questionBankAuditService.joinPage(page, questionBankAudit));
    }

    /**
     * 查询所有数据
     * @param questionBankAudit 查询实体
     * @return 所有数据
     */
    @GetMapping("/selectAll")
    public ResponseResult<List<QuestionBankAudit>> selectAll(QuestionBankAudit questionBankAudit) {
        return ResponseResult.success(questionBankAuditService.list(new QueryWrapper<>(questionBankAudit)));
    }

    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne/{id}")
    public ResponseResult<QuestionBankAudit> selectOne(@PathVariable("id") Long id) {
        return ResponseResult.success(questionBankAuditService.getById(id));
    }

    /**
     * 新增数据
     * @param questionBankAudit 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public ResponseResult<Boolean> insert(QuestionBankAudit questionBankAudit) {
        return ResponseResult.success(questionBankAuditService.save(questionBankAudit));
    }

    /**
     * 修改数据
     * @param questionBankAudit 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public ResponseResult<Boolean> update(QuestionBankAudit questionBankAudit) {
        return ResponseResult.success(questionBankAuditService.updateById(questionBankAudit));
    }

    /**
     * 删除数据
     * @param idList 主键集合
     * @return 删除结果
     */
    @DeleteMapping("/batchDelete")
    public ResponseResult<Boolean> batchDelete(@RequestParam("idList") List<Long> idList) {
        return ResponseResult.success(questionBankAuditService.removeByIds(idList));
    }

    /**
     * 根据题库id改变题库的公共题库属性并在QuestionBankAudit中删除该条记录
     * @param idList 题库id
     * @return 操作结果
     */
    @DeleteMapping("/batchThrough")
    public ResponseResult<Boolean> batchThrough(@RequestParam("idList") List<Long> idList) {
        return ResponseResult.success(questionBankAuditService.batchThrough(idList));
    }

    /**
     * 在QuestionBankAudit中删除该条记录
     * @param idList 题库id
     * @return 操作结果
     */
    @DeleteMapping("/batchRejected")
    public ResponseResult<Boolean> batchRejected(@RequestParam("idList") List<Long> idList) {
        return ResponseResult.success(questionBankAuditService.delBatchByQuestionBankId(idList));
    }

    @GetMapping("/getQuestionBankAuditCount")
    public ResponseResult<Integer> getQuestionBankAuditCount() {
        return ResponseResult.success(questionBankAuditService.count());
    }
}

